/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.grupo.model.DAO;

import com.grupo.model.VO.Prova;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


/**
 *
 * @author Romulo
 */
public class ProvaDAO extends DAO {
    public void cadastrar(Prova c) throws Exception{
        openDataBase();
        String sql = "insert into tabela(nome,telefone)values(?,?)";
        pstmt=con.prepareStatement(sql);
        pstmt.setString(1,c.getNome());
        pstmt.setString(2,c.getTelefone());
        pstmt.execute();
        closeDataBase();
   
    }
      public  List<Prova> listaClientes()throws Exception{
        openDataBase();
        String sql = "select * from tabela";
        pstmt = con.prepareStatement(sql);
        rs = pstmt.executeQuery();
        Prova c=null;        
        List<Prova> listaClientes = new ArrayList<Prova>();
        while(rs.next()){
            c = new Prova();
            c.setId(rs.getInt("id"));
            c.setNome(rs.getString("nome"));
            c.setTelefone(rs.getString("telefone"));
            listaClientes.add(c);
        }
        return listaClientes;
    }
      
    public void delete(Prova c)throws Exception{
        openDataBase();
        String sql = "delete from tabela where id=?";
        pstmt=con.prepareStatement(sql);
        pstmt.setInt(1,c.getId());
        pstmt.execute();
    } 
    
    
    public void update(Prova c) throws Exception{
        openDataBase();
        String sql = "update tabela set nome = ?,telefone = ? where id=?";
        pstmt=con.prepareStatement(sql);
        pstmt.setString(1,c.getNome());
        pstmt.setString(2,c.getTelefone());
        pstmt.setInt
                (3,c.getId());
        pstmt.executeUpdate();
        closeDataBase();
    }
    public Prova buscaPorId(Integer id)throws Exception{
        openDataBase();
        String sql = "select * from tabela where id=?"; 
        pstmt = con.prepareStatement(sql);
        pstmt.setInt(1,id);
        rs = pstmt.executeQuery();
        Prova c = null;
        if(rs.next()){
            c = new Prova();
            c.setId(rs.getInt("id"));
            c.setNome(rs.getString("nome"));
            c.setTelefone(rs.getString("telefone"));
        }        
        return c;
        
    }

}
